import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
# 读取excel 数据
filename = r"D:\Workspaces\study\Python\SimpleCode-Python\北京10年天气数据 (1).xlsx"
df=pd.read_excel(filename,engine="openpyxl")
# 设置matplotlib的字体和字符显示
plt.rcParams['font.family'] = 'SimHei'
plt.rcParams['axes.unicode_minus'] = False
# 生成弧度值并创建闭环
dim_num = 7
radians = np.linspace(0, 2 * np.pi, dim_num, endpoint=False)
radians = np.concatenate((radians, [radians[0]]))
# 统计温度等级列 每种出现的次数
value_counts=df["温度等级"].value_counts()
# 按出现顺序排序
score_a=np.array(value_counts.sort_values(ascending=False))
score_a=np.concatenate((score_a, [score_a[0]])) 
print(score_a)
# 把温度等级列的值去重
radar_labels = df["温度等级"].unique()
print(radar_labels)
# 绘制雷达图
plt.polar(radians, score_a)
radar_labels = np.concatenate((radar_labels, [radar_labels[0]])) 
angles = radians * 180/np.pi  
plt.thetagrids(angles, labels=radar_labels) 

tables = plt.fill(radians,score_a,alpha=0.25)
plt.title("北京10年天气数据")
plt.show()